import { getCategoryList } from '@/api/index'
import store from '..'
import { topCategory } from '@/utils/constant'
export default {
    namespaced: true,
    state: () => {
        return {
            cateList: topCategory,//默认值，如果请求不到数据时则显示
        }
    },
    //做同步操作
    mutations: {
        setList(state, payload) {
            state.cateList = payload
        }
    },
    //做异步操作
    actions: {
        // 请求后台，加载分类数据
        async getAllCategory({ commit }) {
            try {
                //发送请求，请求所有分类类别
                const res = await getCategoryList()
                console.log(res.data.cateList);
                if (res.code === '200') {
                    commit('setList', res.data.cateList)
                }
            } catch (error) {
                console.log(error);
            }
        }
    },
}